package com.hd.service.sqlexcel.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hd.dao.BaseDao;
import com.hd.entity.sqlexcel.SqlExcelReport;
import com.hd.entity.sqlexcel.SqlReportType;
import com.hd.service.sqlexcel.SqlReportTypeService;
import com.hd.util.result.PageInfo;
/**
* 报表类型
*/
@Service("sqlReportTypeService")
public class SqlReportTypeServiceImpl implements SqlReportTypeService {
    private static final Integer STATUS=1;
    @Autowired
    private BaseDao<SqlReportType,String>sqlReportTypeDao;
    @Autowired
    private BaseDao<SqlExcelReport,String>sqlExcelReportDao;
    @Override
    public void save(SqlReportType sqlReportType) {
		sqlReportType.setId(UUID.randomUUID().toString());
		sqlReportType.setStatus(STATUS);
       sqlReportTypeDao.save(sqlReportType);
    }

    @Override
    public void delete(String id){
      sqlReportTypeDao.delete(SqlReportType.class,id);
      String hql="update SqlExcelReport set type='' and typeName='' where type=?";
      sqlExcelReportDao.execute(hql, id);
    }
       

    @Override
    public void update(SqlReportType sqlReportType) {
        SqlReportType vo=sqlReportTypeDao.get(SqlReportType.class,sqlReportType.getId());
        sqlReportType.setStatus(STATUS);
        sqlReportTypeDao.update(sqlReportType);
    }
    @Override
    public SqlReportType get(String id){
    	return sqlReportTypeDao.get(SqlReportType.class, id);
    }
        

    @Override
    public void selectDataGrid(PageInfo pageInfo) {
        String hql="from SqlReportType where 1=1 ";
        Map<String,Object>condition=pageInfo.getCondition();
        List<Object> params=new ArrayList<Object>();
        hql+=" and status="+STATUS;
        if(!pageInfo.getSort().equals("")) {
            hql+=" order by "+pageInfo.getSort()+" "+pageInfo.getOrder();
        }
        List<SqlReportType> sqlReportTypes=sqlReportTypeDao.findPage(hql, pageInfo.getNowpage(), pageInfo.getPagesize(),params);
        pageInfo.setRows(sqlReportTypes);
        String countHql="select count(*) "+hql;
        int total=Integer.parseInt(sqlReportTypeDao.getCountByList(countHql,params).toString());
        pageInfo.setTotal(total);
    }

	@Override
	public List<SqlReportType> findAll() {
		String hql="from SqlReportType where 1=1 and status="+STATUS;
		return sqlReportTypeDao.find(hql);
	}

    @Override
    public void updateStatus(Integer status, String id) {
        String hql="update SqlReportType set status=? where id=?";
        sqlExcelReportDao.execute(hql,status,id);
    }
}
